CentOS 7
Sponsored Link

OpenStack Liberty : Add VM Images
2015/11/15
 
Add Virtual Machine images in Glance.
[1] Load environment variables first.
[root@dlp ~]#
unset OS_TOKEN OS_URL

[root@dlp ~]#
vi ~/keystonerc
export OS_PROJECT_DOMAIN_ID=default
export OS_USER_DOMAIN_ID=default
export OS_PROJECT_NAME=admin
export OS_TENANT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=adminpassword
export OS_AUTH_URL=http://10.0.0.30:35357/v3
export OS_IDENTITY_API_VERSION=3
export PS1='[\u@\h \W(keystone)]\$ '
[root@dlp ~]#
chmod 600 ~/keystonerc

[root@dlp ~]#
source ~/keystonerc

[root@dlp ~(keystone)]#
echo "source ~/keystonerc " >> ~/.bash_profile
# display status (it's OK if no errors are shown)

[root@dlp ~(keystone)]#
glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
[2] For example, Create a Virtual Machine image of CentOS 7.
# create a directory for disk image

[root@dlp ~(keystone)]#
mkdir -p /var/kvm/images
# create a disk image

[root@dlp ~(keystone)]#
qemu-img create -f qcow2 /var/kvm/images/centos7.img 10G
# install

[root@dlp ~(keystone)]#
virt-install \
--name centos7 \
--ram 2048 \
--disk path=/var/kvm/images/centos7.img,format=qcow2 \
--vcpus 2 \
--os-type linux \
--os-variant rhel7 \
--graphics none \
--console pty,target_type=serial \
--location 'http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/' \
--extra-args 'console=ttyS0,115200n8 serial'
Starting install...    
# installation starts
[3]
After installation, change settings in virtual machine like follows and shutdown it.
* delete or comment out the line "HWADDR" and "UUID" in /etc/sysconfig/network-scripts/ifcfg-eth0
* set "dhcp" for "BOOTPROTO" in /etc/sysconfig/network-scripts/ifcfg-eth0
[4] Add the virtual image to Glance.
[root@dlp ~(keystone)]#
glance image-create --name "CentOS7" --file /var/kvm/images/centos7.img --disk-format qcow2 --container-format bare --visibility public

+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | 6e3f655b68891629f09ff9c70aa1de12     |
| container_format | bare                                 |
| created_at       | 2015-11-14T12:13:19Z                 |
| disk_format      | qcow2                                |
| id               | 34beed31-2971-43f0-9c5a-d39d3df1d501 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | CentOS7                              |
| owner            | d625e02b3d394afbad250def2f88fefa     |
| protected        | False                                |
| size             | 1012269056                           |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2015-11-14T12:13:24Z                 |
| virtual_size     | None                                 |
| visibility       | public                               |
+------------------+--------------------------------------+

[root@dlp ~(keystone)]#
glance image-list

+--------------------------------------+---------+
| ID                                   | Name    |
+--------------------------------------+---------+
| 34beed31-2971-43f0-9c5a-d39d3df1d501 | CentOS7 |
+--------------------------------------+---------+
[5] By the way, if you got an image from internet, it's OK to simply add it like follows.
root@dlp:~#
wget http://cloud-images.ubuntu.com/releases/14.04.3/release/ubuntu-14.04-server-cloudimg-amd64-disk1.img -P /var/kvm/images
root@dlp:~#
glance image-create --name "Ubuntu1404" --file /var/kvm/images/ubuntu-14.04-server-cloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare --visibility public

+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | 4263306b9755eade84578f8ca27f8164     |
| container_format | bare                                 |
| created_at       | 2015-11-14T12:16:12Z                 |
| disk_format      | qcow2                                |
| id               | d3c09925-4eb1-40c7-ba18-d27d496eb64a |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | Ubuntu1404                           |
| owner            | d625e02b3d394afbad250def2f88fefa     |
| protected        | False                                |
| size             | 258671104                            |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2015-11-14T12:16:13Z                 |
| virtual_size     | None                                 |
| visibility       | public                               |
+------------------+--------------------------------------+
 
Tweet